package com.alibaba.csp.sentinel.dashboard.rule.nacos;

import java.util.Objects;
import java.util.Properties;
import org.springframework.boot.context.properties.ConfigurationProperties;

import static com.alibaba.nacos.api.PropertyKeyConst.CLUSTER_NAME;
import static com.alibaba.nacos.api.PropertyKeyConst.NAMESPACE;
import static com.alibaba.nacos.api.PropertyKeyConst.PASSWORD;
import static com.alibaba.nacos.api.PropertyKeyConst.SERVER_ADDR;
import static com.alibaba.nacos.api.PropertyKeyConst.USERNAME;

@ConfigurationProperties(prefix = "sentinel.nacos")
public class NacosConfigProperties {

  boolean enabled = false;

  /**
   * nacos discovery server address.
   */
  private String serverAddr;

  /**
   * the nacos authentication username.
   */
  private String username;

  /**
   * the nacos authentication password.
   */
  private String password;


  /**
   * namespace, separation registry of different environments.
   */
  private String namespace="sentinel_rules";

  /**
   * cluster name for nacos .
   */
  private String clusterName;

  /**
   * group name for nacos.
   */
  private String group = NacosConfigUtil.GROUP_ID;

  public Properties assembleConfigServiceProperties() {

    Properties properties = new Properties();
    properties.put(SERVER_ADDR, Objects.toString(this.serverAddr, ""));
    properties.put(USERNAME, Objects.toString(this.username, ""));
    properties.put(PASSWORD, Objects.toString(this.password, ""));
    properties.put(NAMESPACE, Objects.toString(this.namespace, ""));
    properties.put(CLUSTER_NAME, Objects.toString(this.clusterName, ""));
    return properties;
  }

  public boolean isEnabled() {

    return enabled;
  }

  public void setEnabled(boolean enabled) {

    this.enabled = enabled;
  }

  public String getServerAddr() {

    return serverAddr;
  }

  public void setServerAddr(String serverAddr) {

    this.serverAddr = serverAddr;
  }

  public String getUsername() {

    return username;
  }

  public void setUsername(String username) {

    this.username = username;
  }

  public String getPassword() {

    return password;
  }

  public void setPassword(String password) {

    this.password = password;
  }

  public String getNamespace() {

    return namespace;
  }

  public void setNamespace(String namespace) {

    this.namespace = namespace;
  }

  public String getClusterName() {

    return clusterName;
  }

  public void setClusterName(String clusterName) {

    this.clusterName = clusterName;
  }

  public String getGroup() {

    return group;
  }

  public void setGroup(String group) {

    this.group = group;
  }

}
